package com.zim.analysis.saika;

import com.zim.analysis.po.AckPO;

public class Ack0001 extends BaseHandle {

    public Ack0001(byte[] bytes) throws Exception {
        super(bytes);
    }
    
    public AckPO analysis() throws Exception{
        AckPO ackInfo = new AckPO();
        
        ackInfo.setMessage(stringMsg);
        
        ackInfo.setLength(validate());
        
        ackInfo.setDeviceName(stringMsg.substring(2, 22));
        
        ackInfo.setSerialNumber(message[11]);
        
        ackInfo.setTime(System.currentTimeMillis());
        
        switch (message[17]) {
            case 0x06:
                // 心跳
                ackInfo.setAckType("HEART");
            
            case 0x08:
                // 升级
                ackInfo.setAckType("UPGRADEDEVICE");
                break;
            case 0x09:
                // 远程开/关锁
                ackInfo.setAckType("LOCK");
                break;
            case 0x0a:
                // 远程启/停
                ackInfo.setAckType("IGNITE");
                break;
            case 0x0c:
                // 鸣笛
                ackInfo.setAckType("WHISTLE");
                break;
            case 0x0d:
                // 蓝牙复位
                ackInfo.setAckType("BLUETOOTHRESET");
                break;
            case 0x0e:
                // 改蓝牙密码
                ackInfo.setAckType("BLUETOOTHPASS");
                break;
            case 0x0f:
                // 拍照
                ackInfo.setAckType("PHOTO");
                break;
            case 0x10:
                // 长租
                ackInfo.setAckType("RENT");
            case 0x11:
                // 秘钥
                ackInfo.setAckType("SECRET");
                break;
            default:
                throw new Exception("data is invalid");
        }
        
        ackInfo.setRequestSerial(message[18]);
        
        //档位
        switch ((message[19] & 0x70)>>4) {
            case 0:
                ackInfo.setGear("E/S");
                break;
            case 1:
                ackInfo.setGear("R");
                break;
            case 2:
                ackInfo.setGear("N");
                break;
            case 3:
                ackInfo.setGear("D");
                break;
            case 4:
                ackInfo.setGear("P");
                break;
            default:
                ackInfo.setGear("null");
                break;
        }
        
        //车速
        ackInfo.setSpeed((message[19] & 0x08)>>3);

        //行车灯/示宽灯，1为开，0为关
        ackInfo.setRunLight((message[19] & 0x04)>>2);
        
        //状态
        ackInfo.setStatus(message[19] & 0x03);
        
        return ackInfo;
        
    }
}
